package com.chen.serviceprice.controller;

import com.chen.internalcommon.dto.PriceRule;
import com.chen.internalcommon.dto.ResponseResult;
import com.chen.internalcommon.request.PriceRuleIsNewRequest;
import com.chen.serviceprice.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenLiuPing
 **/
@RestController
@RequestMapping("/price-rule")
public class PriceRuleController {

    @Autowired
    private PriceRuleService priceRuleService;

    /**
     * 添加计价规则
     * @param priceRule
     * @return
     */
    @PostMapping("/add")
    public ResponseResult add(@RequestBody PriceRule priceRule) {
        return priceRuleService.add(priceRule);
    }

    /**
     * 修改计价规则
     * @param priceRule
     * @return
     */
    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule) {
        return priceRuleService.edit(priceRule);
    }

    /**
     * 判断计价规则是否最新
     */
    @PostMapping("is-new")
    public ResponseResult isNew(@RequestBody PriceRuleIsNewRequest priceRuleIsNewRequest) {
        return priceRuleService.isNew(priceRuleIsNewRequest.getFareType(), priceRuleIsNewRequest.getFareVersion());
    }

    /**
     * 查询最新的计价规则
     */
    @PostMapping("/get-newest-version")
    public ResponseResult getNewestVersion(@RequestParam String fareType) {
        return priceRuleService.getNewestVersion(fareType);
    }

    /**
     * 根据城市编码和车型查询对应计价规则是否存在
     */
    @PostMapping("/if-exists")
    public ResponseResult ifExists(@RequestBody PriceRule priceRule) {
        String cityCode = priceRule.getCityCode();
        String vehicleType = priceRule.getVehicleType();
        return priceRuleService.ifExists(cityCode, vehicleType);
    }




}
